web browserで複数のファイルを一括downloadする
/icons/javascript.icon
一旦圧縮してからdownloadするのが無難そう
dependencies
code:ts
type Data = {
data: Blob;
fileName: string;
}[];
code:script.js
import {installCDN} from '../scrapbox-install-CDN/script.js';
const installed = await installCDN({
id: 'scrapbox-userscript-jszip',
src: '//cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js'
});
export async function zipAll(data, folderName) {
await installed;
let zip = new JSZip();
let folder = folderName ? zip.folder(folderName) : zip;
data.forEach(({data, fileName}) => folder.file(${fileName}.${data.type.match(/^[^\/]+\/(.*)$/)[1]}, data));
return {
data: await zip.generateAsync({type: "blob"}),
fileName: ${folderName}.zip,
};
}
Reference